package org.luxor.common.netty.protocol.handler.send;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.luxor.common.netty.protocol.NettyMessageIdVariableHeader;
import org.luxor.common.netty.protocol.message.NettyPubCompMessage;
import org.luxor.common.netty.protocol.message.NettyPubRelMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 消息释放
 *
 * @author Mr.yan @date 2023/12/8
 */
public class SendRelMessageHandler extends SimpleChannelInboundHandler<NettyPubRelMessage> {
    private static final Logger log = LoggerFactory.getLogger(SendRelMessageHandler.class);

    @Override
    public void channelRead0(ChannelHandlerContext ctx, NettyPubRelMessage nettySendRelMessage) {
        NettyMessageIdVariableHeader messageIdVariableHeader = nettySendRelMessage.variableHeader();
        String messageId = messageIdVariableHeader.messageId();
        //	构建返回报文
        NettyPubCompMessage sendCompleteMsg = NettyPubCompMessage.from(messageId);
        ctx.channel().writeAndFlush(sendCompleteMsg);
    }
}
